package com.caird.pmp.iot.message.impl;

import com.caird.pmp.iot.message.MessageBase;
import com.caird.pmp.iot.message.MessageUtils;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.util.Date;

@Data
public class DeviceMessage01E1 extends MessageBase {

    public DeviceMessage01E1() {
        setId((short)0x01E1);
    }

    @Override
    public boolean decodeBody(ByteBuf raw) {

        if (getBodyLength() < 18)
            return false;

        //时间戳
        byte[] bs = new byte[6];
        raw.readBytes(bs);
        date = MessageUtils.decodeDate(bs);

        //复位流水号
        resetNo = raw.readInt();

        //日志流水号
        logNo = raw.readInt();

        //日志ID
        logId = raw.readShort();

        //日志长度
        logLength = raw.readShort();

        if (getBodyLength() < 18 + logLength)
            return false;

        //日志
        bs = new byte[logLength];
        raw.readBytes(bs);
        log = new String(bs);

        return true;
    }


    //时间戳
    private Date date;

    //复位流水号
    private int resetNo;

    //日志流水号
    private int logNo;

    //日志ID
    private short logId;

    //日志
    private short logLength;

    //日志
    private String log;
}
